package com.lxy.demo.servlet;

import com.lxy.demo.entity.UserDemo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@WebServlet(name = "Servlet1", urlPatterns = "/Servlet1")
public class Servlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        List<String> list = Arrays.asList("aaa","bbb","ccc");
        request.setAttribute("list",list);
        request.setAttribute("username","888");
        List<UserDemo> userDemos = new ArrayList<>();
        userDemos.add(new UserDemo("花姑娘","123"));
        userDemos.add(new UserDemo("菜姑娘","333"));
        request.setAttribute("userdemo",userDemos);
        request.setAttribute("date",new Date());
        request.setAttribute("aaa",5.505);
        request.getRequestDispatcher("/test03.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
